package b.gate.utils.trying

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json._

/**
  * 贲国称 于 2016/11/29 创建。
  */

case class Person(id: Int, name: String)

trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
  implicit val f1 = jsonFormat2(Person)
}

object TryJSON extends App with JsonSupport {
  val p1 = Person(1, "abc")
  val p1str = p1.toJson.toString()
  println(p1str)
  val json = p1str.parseJson
  val p2 = json.convertTo[Person]
  println(p2)
}
